using System;
using Kopernikus.Parsing.Utility;

namespace Kopernikus.Parsing.Earley
{
    public struct EarleySetItem : IEquatable<EarleySetItem>
    {
        public static readonly EarleySetItem None = Create(EarleyItem.None, -1);
        private Pair<EarleyItem, int> m_data;

        public EarleyItem Item
        {
            get { return m_data.First; }
        }

        public int SetIndex
        {
            get { return m_data.Second; }
        }

        #region Object overrides

        public override string ToString()
        {
            return m_data.ToString();
        }

        public override bool Equals(object obj)
        {
            return Equals((EarleySetItem) obj);
        }

        public override int GetHashCode()
        {
            return m_data.GetHashCode();
        }

        #endregion

        #region IEquatable<EarleySetItem> Members

        public bool Equals(EarleySetItem other)
        {
            return m_data.Equals(other.m_data);
        }

        #endregion

        public static EarleySetItem Create(EarleyItem item, int setIndex)
        {
            EarleySetItem earleySetItem;
            earleySetItem.m_data = Pair<EarleyItem, int>.Create(item, setIndex);
            return earleySetItem;
        }
    }
}